package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.Dto.AdminDto;
import org.example.RabbitMq.Service.UserService;
import org.example.pojos.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * @Author : zhangbo
 * @data : 2024/7/15
 * @description :
 */
@Slf4j
@RestController
@RequestMapping("/subside")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 根据手机查询
     * @param phone
     * @return
     */
    @GetMapping("/getUser/ByPhone")
    public Admin getUserByPhone(String phone) {
        List<Admin> list = userService.findByPhone(phone);
        if (list.size() == 0 && StringUtils.isEmpty(list)) return null;
        return list.stream().findFirst().get();
    }

    /**
     * 随机插入用户接口
     * @return
     * @throws ParseException
     */
    @GetMapping("/getUser/random")
    public String randomInsert( ) throws ParseException {
       return userService.insertBatch();
    }

    /**
     * 根据登陆时间，修改status
     * @return
     */
    @GetMapping("/changeUser/Status")
    public String changeStatus(Date timme) {
        return userService.changeStatus(timme);
    }
    /**
     * 根据登陆时间，修改status
     * @return
     */
    @RequestMapping (value = "/changeUser/Status",method = RequestMethod.POST)
    public String changeStatus1(Date timme) {
        return userService.changeStatus(timme);
    }

}
